package com.pk.platform.business.apply.web;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.pk.platform.business.apply.service.IVacationService;
import com.pk.platform.business.apply.vo.VacationVO;
import com.pk.platform.business.flow.web.FlowExecuteAction;
import com.pk.platform.domain.apply.Vacation;
import com.pk.platform.domain.data.Employee;
import com.pk.platform.util.DateConverter;
import com.pk.platform.util.StringConverter;
import com.pk.platform.util.constant.Constant;

@ParentPackage(value="default")
@Namespace(value="/inner/vacation")
public class VacationAction extends FlowExecuteAction {

	private IVacationService vacationService;
	
	private VacationVO vvo = new VacationVO();
	
	private Vacation vacation = new Vacation();
	
	private Employee employee = new Employee();
	
	private String[] jqg_listGrid;
	
	@Action(value="vacationManage",
			results={@Result(name="success", 
					location="/jsp/login/business/apply/vacation/vacationManage.jsp")})
	public String vacationManage()
	{
		super.initGrid();
		return SUCCESS;
	}
	
	@Action(value="toSaveVacation",
			results={@Result(name="success", 
					location="/jsp/login/business/apply/vacation/saveVacation.jsp")})
	public String toSaveVacation()
	{
		if(StringConverter.isNotNull(vacation.getId()))
		{
			vacation = vacationService.queryVacationById(vacation.getId());
		}
		super.setFlowInfo(vacation);
		return SUCCESS;
	}
	
	@Action(value="saveVacation",
			results={@Result(name="success", 
					type="json",
					params={"root", "docId"})})
	public String saveVacation()
	{
		vacation.setFromTime(DateConverter.StringToDate(vacation.getFromTimeStr(), DateConverter.FORMAT_SIX));
		vacation.setToTime(DateConverter.StringToDate(vacation.getToTimeStr(), DateConverter.FORMAT_SIX));
		vacationService.saveVacation(vacation);
		docId = vacation.getId();
		return SUCCESS;
	}
	
	@Action(value="delVacation",
			results={@Result(name="success", 
					type="json")})
	public String delVacation()
	{
		if(jqg_listGrid != null)
		{
			for(String vid : jqg_listGrid)
			{
				vacationService.delVacation(vid);
			}
		}
		return SUCCESS;
	}

	@Action(value="taskVacationManage",
			results={@Result(name="success", 
					location="/jsp/login/business/apply/vacation/taskVacationManage.jsp")})
	public String taskVacationManage()
	{
		return SUCCESS;
	}
	
	@Action(value="queryTaskVacation",
			results={@Result(name="success", 
					type="json",
					params={"includeProperties", Constant.INCLUDE_PROPERTIES})})
	public String queryTaskVacation()
	{
		list = vacationService.queryTaskVacationList(vvo, pager);
		return SUCCESS;
	}
	
	public IVacationService getVacationService() {
		return vacationService;
	}

	public void setVacationService(IVacationService vacationService) {
		this.vacationService = vacationService;
	}

	public VacationVO getVvo() {
		return vvo;
	}

	public void setVvo(VacationVO vvo) {
		this.vvo = vvo;
	}

	public Vacation getVacation() {
		return vacation;
	}

	public void setVacation(Vacation vacation) {
		this.vacation = vacation;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public String[] getJqg_listGrid() {
		return jqg_listGrid;
	}

	public void setJqg_listGrid(String[] jqgListGrid) {
		jqg_listGrid = jqgListGrid;
	}
	
}
